package cc.verywell.pureblock.msg.nfs.linkmap;

import java.util.concurrent.PriorityBlockingQueue;

/**
* 
* Copyright © 2019 TanYaqiu. All rights reserved.
* @author TanYaqiu 
* @address flat 601
* @date 2019年6月16日 下午3:24:34
*/
public class EasyIteratorGroup implements EasyIterator{

	final PriorityBlockingQueue<EasyIterator> que;
	public EasyIteratorGroup() {
		this.que = new PriorityBlockingQueue<>();
	}

	private LinkCell current;
	@Override
	public boolean hasNext() {
		return current!=null;
	}

	@Override
	public LinkCell next() {
		LinkCell cr = current;
		//LinkCell last = cr; 
		current = null;
		EasyIterator ie;
		while(null!=(ie=que.peek())) {
			LinkCell nxt = ie.next();
			if(ie.hasNext()) {
				que.add(ie);
			}
			if(!nxt.equalsWithoutSeq(cr, 0)) {
//				if(nxt.isRemove()) {
//					last = nxt;
//				}else {
					current = nxt;
					break;
//				}
			}
		}
		return cr;
	}

	@Override
	public LinkCell current() {
		EasyIterator ie = que.peek();
		if(ie==null)return null;
		return ie.current();
	}
	
	public void add(EasyIterator it) {
		if(it.hasNext())que.add(it);
	}
	

}
